*****************************************************************************************************************************************************************
*************************************************** MOTIVATED REASONING IN THE AFTERMATH OF THE BREXIT VOTE *****************************************************
*****************************************************************************************************************************************************************


********************************************************************************
***************************** BES PANEL DATA ANALYSIS **************************
********************************************************************************



******************************************************
************** DATA IMPORT & CLEANING ****************
******************************************************

* SET WORKING DIRECTORY HERE

**download BES waves 1-14 from: http://www.britishelectionstudy.com/data-objects/panel-study-data/

use "BES2015_W1_v7.9.dta", clear
gen wave =1
order wave, after(id)
save "W1.dta", replace

use "BES2015_W2_v6.9.dta", clear
gen wave =2
order wave, after(id)
save "W2.dta", replace

use "BES2015_W3_v4.9.dta", clear
gen wave =3
order wave, after(id)
save "W3.dta", replace

use "BES2015_W4_v3.9.dta", clear
gen wave =4
order wave, after(id)
save "W4.dta", replace

use "BES2015_W5_v3.9.dta", clear
gen wave =5
order wave, after(id)
save "W5.dta", replace

use "BES2015_W6_v3.9.dta", clear
gen wave =6
order wave, after(id)
save "W6.dta", replace

use "BES2015_W7_v2.2-1.dta", clear
gen wave =7
order wave, after(id)
save "W7.dta", replace

use "BES2015_W8_v2.3.dta", clear
gen wave =8
order wave, after(id)
save "W8.dta", replace

use "BES2015_W9_v1.7.dta", clear
gen wave =9
order wave, after(id)
save "W9.dta", replace

use "BES2015_W10_v0.8.dta", clear
gen wave =10
order wave, after(id)
save "W10.dta", replace

use "BES2015_W11_v1.5.dta", clear
gen wave =11
order wave, after(id)
save "W11.dta", replace

use "BES2015_W12_v1.5.dta", clear
gen wave =12
order wave, after(id)
save "W12.dta", replace

use "BES2017_W13_v1.5.dta", clear
gen wave =13
order wave, after(id)
save "W13.dta", replace

use "BES2017_W14_v0.4.dta", clear
gen wave =14
order wave, after(id)
save "W14.dta", replace



use "W1.dta"
append using "W2.dta" "W3.dta" "W4.dta" "W5.dta" "W6.dta" "W7.dta" "W8.dta" "W9.dta" "W10.dta" "W11.dta" "W12.dta" "W13.dta" "W14.dta"

order starttime endtime, after(wave)


save "APPENDED W1-W14.dta", replace



tab generalElectionVote, miss

recode generalElectionVote  9999=0
lab def pty 0 "abstain/DK" 1 "Conservative" 2 "Labour" 3 "Liberal Democrat" 4 "SNP" 5 "Plaid Cymru" ///
			6 "UKIP" 7 "Green Party" 8 "BNP" 9 "Other"
lab values generalElectionVote pty



tab euRefVote 

recode euRefVote 0=7 9999=0 2=0 1=2 
recode euRefVote 7=1
lab def ref 0 "abstain/DK" 1 "Remain" 2 "Leave"
lab values euRefVote ref

	
		
gen Voted2016 =.
replace Voted2016 = 1 if profile_eurefturnout ==1 & wave ==10 
replace Voted2016 = 0 if profile_eurefturnout ==0 & wave ==10
replace Voted2016 = 0 if profile_eurefturnout ==9999 & wave ==10


bysort id (Voted2016): replace Voted2016 = Voted2016[1]	
tab Voted2016, miss	


gen altVoted2016 =.
replace altVoted2016 = 1 if profile_eurefturnout ==1 & wave ==11 
replace altVoted2016 = 0 if profile_eurefturnout ==0 & wave ==11
replace altVoted2016 = 0 if profile_eurefturnout ==9999 & wave ==11

bysort id (altVoted2016): replace altVoted2016 = altVoted2016[1]				
tab altVoted2016, miss


replace Voted2016 = altVoted2016 if Voted2016 ==.

tab Voted2016, miss


tab age wave, miss

tab ageGroup wave, miss

*combining

tab ageGroup, nol
recode ageGroup 1=0 2=1 3=2 4=3 5=4 6=5 7=6
lab def agegr 0 "Under 18" 1 "18-25" 2 "26-35" 3 "36-45" 4 "46-55" 5 "56-65" 6 "66+", replace
lab values ageGroup agegr

gen ageGroup_complement =.
replace ageGroup_complement = 0 if age <18
replace ageGroup_complement = 1 if age >=18 & age <=25
replace ageGroup_complement = 2 if age >=26 & age <=35
replace ageGroup_complement = 3 if age >=36 & age <=45
replace ageGroup_complement = 4 if age >=46 & age <=55
replace ageGroup_complement = 5 if age >=56 & age <=65
replace ageGroup_complement = 6 if age >=66
replace ageGroup_complement =. if age ==.
lab values ageGroup_complement agegr


gen ageGroup1 = ageGroup_complement
replace ageGroup1 = ageGroup if ageGroup_complement==.
lab values ageGroup1 agegr

order age ageGroup ageGroup_complement ageGroup1, after (wave)

mdesc ageGroup ageGroup1

*need to impute age for remaining missing values

bysort id : egen avgAgeGroup=mean(ageGroup1)
order avgAgeGroup, after (ageGroup1)
replace avgAgeGroup=round(avgAgeGroup, 1)
lab values avgAgeGroup agegr

replace ageGroup1 = avgAgeGroup if ageGroup1 ==.


recode gender 1=0 2=1, gen(female)

lab define wavedat 1 "Feb/Mar'14" 2 "May/Jun'14" 3 "Sept/Oct'14" 4 "Mar'15" 5 "Apr/May'15" 6 "May '15" ///
	7 "Apr/May'16" 8 "May/Jun'16" 9 "Jun/Jul'16" 10 "Nov/Dec'16" 11 "Apr/May'17" 12 "May/Jun'17" 13 "Jun'17" ///
	14 "May '18"

lab values wave wavedat

recode profile_gross_personal 16/9999=.

recode profile_gross_personal 1=0 2=1 3=2 4=3 5=4 6=5 7=6 8=7 9=8 10=9 11=10 12=11 13=12 14=13 .=99
lab def inc 0 "Under £5,000 per year" 1 "£5,000 to £9,999 per year" 2 "£10,000 to £14,999 per year" ///
	3 "£15,000 to £19,999 per year" 4 "£20,000 to £24,999 per year" 5 "£25,000 to £29,999 per year" ///
	6 "£30,000 to £34,999 per year" 7 "£35,000 to £39,999 per year" 8 "£40,000 to £44,999 per year" ///
	9 "£45,000 to £49,999 per year" 10 "£50,000 to £59,999 per year" 11 "£60,000 to £69,999 per year" ///
	12 "£70,000 to £99,999 per year" 13 "£100,000 and over" 99 "Not Declared"
lab values profile_gross_personal inc

gen Inc =.
replace Inc = 0 if profile_gross_personal <=1
replace Inc = 1 if profile_gross_personal >1 & profile_gross_personal <=3
replace Inc = 2 if profile_gross_personal > 3 & profile_gross_personal <=5
replace Inc = 3 if profile_gross_personal >5 & profile_gross_personal <= 9
replace Inc = 4 if profile_gross_personal >9
replace Inc = 5 if profile_gross_personal == 99
replace Inc = . if profile_gross_personal ==.

lab def inc1 0 "Under £10,000 per year" 1 "£10,000 to £19,999 per year" 2 "£20,000 to £29,999 per year" ///
	3 "£30,000 to £49,999 per year" 4 "£50,000 and over" 5 "Not Declared"
lab values Inc inc1

tab profile_gross_personal Inc
hist Inc


* mean-imputing education using information from other waves

bysort id : egen avgedlevel=mean(edlevel)
order edlevel avgedlevel, after (avgAgeGroup)
replace avgedlevel=round(avgedlevel, 1)
lab values avgedlevel edlevel

replace edlevel = avgedlevel if edlevel ==.

mdesc edlevel




********************************************************************
********************* DEPENDENT VARIABLES **************************
********************************************************************
					
recode changeEconomy 9999=.
recode econGenRetro 9999=.



********************************************************************
********************* MAIN REGRESSION ANALYSIS *********************
********************************************************************

***** Figures 1 & 2 (Manuscript) & Table A1 (Online Appendix) ******



*****************************Current Economy Perceptions

sort id wave 
by id: gen lagchangeEconomy = changeEconomy[_n-1]
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m1


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc =1) atmeans noatlegend saving (margins_1, replace)
estimates store margins_1

combomarginsplot margins_1, recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) 
	
graph save econ.gph, replace
graph export econ.pdf, replace
	
	
*****************************Retrospective Economic Perceptions	
	
	
sort id wave 
by id: gen lageconGenRetro = econGenRetro[_n-1]
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m2


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2, replace)
estimates store margins_2

combomarginsplot margins_2, recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) saving(econretro_gen, replace)

graph export econretro_gen.pdf, replace

esttab m1 m2 using mainmodel.tex, replace label nogap onecell se ar2 




********************************************************************
************************* VOTERS v. ABSTAINERS *********************
********************************************************************

****** Figure 3 (Manuscript) & Tables A6-A7 (Online Appendix) ******


*****************************Current Economy Perceptions

********* Voters

sort id wave 
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==1 ,vce(cluster id)
	
est store m1a


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc = 1) atmeans noatlegend saving (margins_1a, replace)
estimates store margins_1a

combomarginsplot margins_1a, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) subtitle (Voters Subsample, size(small)) saving(econ_Voters, replace)

	

*********** Non-Voters

sort id wave 
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==0 ,vce(cluster id)
	
est store m1b


esttab m1a m1b using voternonvotermodel.tex, replace label nogap onecell se ar2 


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc = 1) atmeans noatlegend saving (margins_1b, replace)
estimates store margins_1b

combomarginsplot margins_1b, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) subtitle (Non-voters Subsample, size(small)) saving(econ_NonVoters, replace)

	
graph combine econ_Voters.gph econ_NonVoters.gph, col(2)
graph export VotersNonVoters.pdf, replace



*****************************Retrospective Economic Perceptions


********* Voters


sort id wave 
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==1 ,vce(cluster id)
	
est store m2a


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2a, replace)
estimates store margins_2a

combomarginsplot margins_2a, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) subtitle (Voters Subsample, size(small)) saving(econretro_gen_Voters, replace)


	
*********** Non-Voters

sort id wave 
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==0 ,vce(cluster id)
	
est store m2b


esttab m2a m2b using voternonvotermodelRETRO.tex, replace label nogap onecell se ar2 


***margins

*profile: Labour, 56-65, A-level, female, income= 10-20k

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2b, replace)
estimates store margins_2b

combomarginsplot margins_2b, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) subtitle (Non-voters Subsample, size(small)) saving(econretro_gen_NonVoters, replace)

	
graph combine econretro_gen_Voters.gph econretro_gen_NonVoters.gph, col(1)
graph export VotersNonVoters_RETRO.pdf, replace	
	
	
graph combine econ_Voters.gph  econretro_gen_Voters.gph econ_NonVoters.gph econretro_gen_NonVoters.gph, col(2)
graph export VOTER-NonVOTER_ALL.pdf, replace	


save "APPENDED W1-W14_Master.dta", replace

clear


********************************************************************************
***************************** EXPERIMENT ANALYSIS ******************************
********************************************************************************

**************** Table 1 & Figures 4 & 5 (Manuscript) *************************


use "YouGovExp.dta"

reshape long Q1 Q2 Q3, i(ID) j(Exp_Group, string)
egen totNA= total(Q1==. | Q1==9999), by(ID)
egen totNA2= total(Q2==. | Q2==9999), by(ID)
egen totNA3= total(Q3==. | Q3==9999), by(ID)
recode Q1 Q2 Q3 (9999=.)
drop if Q1==. & Q2==. & Q3==. 
								*to have 3267 observations back, removing ID duplicates (each id was
								*assigned all four group then filled with missing data)

encode Exp_Group, gen(Group)
label drop Group
recode Group 4=0 1=2 2=1
lab define expgroup 1 "Prime only" 2 "Prime & Info" 3 "Info only" 0 "Control"
label values Group expgroup
order Group, after(Exp_Group) 
save "YouGovExp_Long.dta", replace // added by kt

recode Q1 (4=.)
recode Q3 (999=.)
recode gender 1=0 2=1 8/9999=.,gen(female)
recode education_age 7/9999=.
recode gross_personal_income 15/9999=.
recode Region_GOR 13/9999=.
recode Vote2015 99/9999=.
recode VoteEURef 3/9999=. 1=0 2=1
lab drop VoteEURef
lab def brex 0 "Remain" 1 "Leave"
lab values VoteEURef brex


******************************* Regression Table

regress Q2 i.Group##i.VoteEURef
est store exp1

margins, over(Group VoteEURef) 
marginsplot, scheme(plotplain) ///
	plot1opts(lpattern(none)lcolor(none) mcolor(black) msymbol(circle) msize(small)) ci1opts(col(black)) /// 
	plot2opts(lpattern(none) lcolor(none) mcolor(gs5) msymbol (diamond) msize(small)) ci2opts(col(gs5)) ///
	title(UK economy rank comparison, size(large)) ytitle(Mean UK Rank) xtitle("") xlabel(,labsize(small)) plot( , label("Voted Remain" "Voted Leave"))
	
	
regress Q3 i.Group##i.VoteEURef
margins, over(Group VoteEURef) 
marginsplot, scheme(plotplain) ///
	plot1opts(lpattern(none)lcolor(none) mcolor(black) msymbol(circle) msize(small)) ci1opts(col(black))  /// 
	plot2opts(lpattern(none) lcolor(none) mcolor(gs5) msymbol (diamond) msize(small)) ci2opts(col(gs5)) ///
	title(UK economy is getting better, size(large)) ytitle(Mean Economic Optimism) xtitle("") xlabel(,labsize(small)) plot( , label("Voted Remain" "Voted Leave"))
est store exp2

esttab exp1 exp2 using exp_reg.tex, replace label nogap onecell se r2 n


********************************* CI Bar Plots


cibar Q2, over1(VoteEURef) over2(Group) graphopts(title(UK Economic Growth Rank by 2016 Vote) xtitle(Treatment Group, size(small)) ytitle (Average Rank) ///
	scheme(plotplain) note(YouGov Survey Experiment - July 2018, size(vsmall)) name(graph_1,replace))

graph export "figure4.pdf"

cibar Q3, over1(VoteEURef) over2(Group) graphopts(title(UK Economy is Getting Better by 2016 Vote) xtitle(Treatment Group, size(small)) ytitle (Average Economic Optimism) ///
	scheme(plotplain) note(YouGov Survey Experiment - July 2018, size(vsmall)) name(graph_2,replace))

graph export "figure5.pdf"
	

******************************** Balance Tests

****** Table A10 (Appendix)

tabstat age, by(Group)
tabstat female, by(Group)
tabstat education_age, by(Group) statistics(mean median)
tabstat gross_personal_income, by(Group) statistics(mean median)
tab Region_GOR if Group ==0, miss
tab Region_GOR if Group ==1, miss
tab Region_GOR if Group ==2, miss
tab Region_GOR if Group ==3, miss
tab Vote2015 if Group ==0, miss
tab Vote2015 if Group ==1, miss
tab Vote2015 if Group ==2, miss
tab Vote2015 if Group ==3, miss
tab VoteEURef if Group ==0, miss
tab VoteEURef if Group ==1, miss
tab VoteEURef if Group ==2, miss
tab VoteEURef if Group ==3, miss


oneway age Group
kwallis female, by(Group)
kwallis education_age, by(Group)
kwallis gross_personal_income, by(Group)
kwallis Region_GOR, by(Group)
kwallis Vote2015, by(Group)
kwallis VoteEURef, by(Group)
	

clear
	

	
********************************************************************************
******************************* ROBUSTNESS TESTS *******************************
********************************************************************************


*********************************************
************ ATTRITION TESTS ****************
*********************************************

******* Table  A2 (Online Appendix) *********
use "APPENDED W1-W14.dta"

sort id wave
collapse (count) wave, by(id)
rename wave wave_count
save "numberofwavesbyid.dta", replace

use "APPENDED W1-W14_Master.dta"
merge m:1 id using "numberofwavesbyid.dta"
order wave_count, after (wave)
drop _merge
save "APPENDED W1-W14_Master.dta", replace


drop if wave_count < 14


xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store a1



xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store a2

esttab a1 a2 using attrition_test.tex, replace label nogap onecell se ar2  


clear


*********************************************
************** SORTING TEST *****************
*********************************************

******* Table  A3 (Online Appendix) *********


use "APPENDED W1-W14_Master.dta"


gen EUREFVoted=.
replace EUREFVoted = 0 if euRefVote ==0 & wave==9
replace EUREFVoted = 1 if euRefVote ==1 & wave==9
replace EUREFVoted = 2 if euRefVote ==2 & wave==9
bysort id (EUREFVoted): replace EUREFVoted = EUREFVoted[1]
lab def EUREF 0 "Abstain/DK" 1"Remain" 2 "Leave"
lab values EUREFVoted EUREF
order EUREFVoted euRefVote, before(starttime)
						

sort id wave 
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.EUREFVoted i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store sm1

xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.EUREFVoted i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store sm2


esttab sm1 sm2 using sortingreg.tex, replace label nogap onecell se aic bic  scalars("ll Log lik.")


*********************************************
************* NO PTY CONTROLS ***************
*********************************************

******* Table  A4 (Online Appendix) *********

	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m1_nopty

margins, over(wave euRefVote) at (edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_1nopty, replace)
estimates store margins_1nopty

combomarginsplot margins_1nopty, recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) subtitle (Without Party Controls) saving(econ_nopty, replace)

	

xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m2_nopty


esttab m1_nopty m2_nopty using regressions3.tex, replace label nogap onecell se r2 


*******************************************************
************** 3-WAY INT: PARTISANSHIP ****************
*******************************************************

****** Table  A5 & Figures 1-2 (Online Appendix) ******

set matsize 10000
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.generalElectionVote##i.euRefVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m1pr


***margins

margins, over(wave generalElectionVote euRefVote)  at (edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_1pr, replace)
estimates store margins_1pr

gen pty =.
replace pty = 0 if generalElectionVote == 0
replace pty = 1 if generalElectionVote == 1
replace pty = 2 if generalElectionVote == 2
replace pty = 3 if generalElectionVote >2
lab def ptyy 0 "Abstain/DK" 1 "Conservative" 2 "Labour" 3 "All Other"
lab values pty ptyy

combomarginsplot margins_1pr, by(generalElectionVote) recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) saving(econ_3w, replace)

	
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.generalElectionVote##i.euRefVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store m2pr

esttab m1pr m2pr using withinpty.tex, replace label nogap onecell se ar2


***margins

margins, over(wave generalElectionVote euRefVote) at (edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2pr, replace)
estimates store margins_2pr



combomarginsplot margins_2pr, by(generalElectionVote) recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	saving(econRetro_3w, replace)



	
	
esttab m1pr m2pr using regressions2.tex, replace label nogap onecell se r2 



**************************************************************
************** VOTERS-NON-VOTERS: HIGH EU KNOW ***************
**************************************************************

*************** Tables A8-A9 (Online Appendix) ***************


gen EUcorr1=.
replace EUcorr1 = 1 if euKnow1 == 2
replace EUcorr1 = 0 if euKnow1 == 1
replace EUcorr1 =. if euKnow1 > 2


gen EUcorr2=.
replace EUcorr2 = 1 if euKnow2 == 2
replace EUcorr2 = 0 if euKnow2 == 1
replace EUcorr2 =. if euKnow2 > 2

gen EUcorr3=.
replace EUcorr3 = 1 if euKnow3 == 1
replace EUcorr3 = 0 if euKnow3 == 2
replace EUcorr3 =. if euKnow3 > 2

gen EUcorr4=.
replace EUcorr4 = 1 if euKnow4 == 1
replace EUcorr4 = 0 if euKnow4 == 2
replace EUcorr4 =. if euKnow4 > 2

gen EUcorr5=.
replace EUcorr5 = 1 if euKnow5 == 2
replace EUcorr5 = 0 if euKnow5 == 1
replace EUcorr5 =. if euKnow5 > 2

gen EUcorr6=.
replace EUcorr6 = 1 if euKnow6 == 2
replace EUcorr6 = 0 if euKnow6 == 1
replace EUcorr6 =. if euKnow6 > 2


lab def cor 0"Incorrect" 1"Correct"
lab values EUcorr* cor


egen EUknow = rowtotal(EUcorr1 EUcorr2 EUcorr3 EUcorr4 EUcorr5 EUcorr6), missing



bysort id (EUknow): replace EUknow = EUknow[1]



sum EUknow if wave==8



tab EUknow if wave==8



corr EUknow euRefVote if wave ==9


 
drop if EUknow < 4
drop if EUknow ==.


*****************************Current Economy Perceptions

*********** Voter

sort id wave 
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==1 ,vce(cluster id)
	
est store m1a_know


***margins


margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_1a_know, replace)
estimates store margins_1a_know

combomarginsplot margins_1a_know, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) subtitle (High Knowledge Voters Subsample, size(small)) saving(econ_Voters_know, replace)



*********** Non-Voter

sort id wave 
	
xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==0 ,vce(cluster id)
	
est store m1b_know


esttab m1a_know m1b_know using voternonvotermodel_HIGHKNOW.tex, replace label nogap onecell se ar2 


***margins


margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_1b_know, replace)
estimates store margins_1b_know

combomarginsplot margins_1b_know, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) subtitle (Non-voters Subsample, size(small)) saving(econ_NonVoters_know, replace)

	
graph combine econ_Voters_know.gph econ_NonVoters_know.gph, col(1)
graph export VotersNonVoters_know.pdf, replace



*****************************Retrospective Economic Perceptions
	
*********** Voter

sort id wave 
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==1 ,vce(cluster id)
	
est store m2a_know


***margins


margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2a_know, replace)
estimates store margins_2a_know

combomarginsplot margins_2a_know, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) subtitle (Voters Subsample, size(small)) saving(econretro_gen_Voters_know, replace)

	
*********** Non-Voter

sort id wave 
	
xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc if Voted2016 ==0 ,vce(cluster id)
	
est store m2b_know


esttab m2a_know m2b_know using voternonvotermodelRETRO_HIGHKNOW.tex, replace label nogap onecell se ar2 


***margins


margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_2b_know, replace)
estimates store margins_2b_know

combomarginsplot margins_2b_know, recast(line) ylabel(1(0.5)4.5) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) subtitle (Non-voters Subsample, size(small)) saving(econretro_gen_NonVoters_know, replace)

	
graph combine econretro_gen_Voters_know.gph econretro_gen_NonVoters_know.gph, col(1)
graph export VotersNonVoters_RETRO_know.pdf, replace	





****************************************************
***************** HIGH EU KNOWLEDGE ****************
****************************************************

******** Figure 6 & 7 (Manuscript) Table  A11 (Online Appendix) ********


xtset id wave	
xtreg changeEconomy lagchangeEconomy i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store cue1

***margins

margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_c1, replace)
estimates store margins_c1

combomarginsplot margins_c1, recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy is Getting Better) saving(econ_cue, replace)

	


xtset id wave	
xtreg econGenRetro lageconGenRetro i.wave##i.euRefVote i.generalElectionVote i.edlevel i.ageGroup1 female i.Inc,vce(cluster id)
	
est store cue2

***margins


margins, over(wave euRefVote) at (generalElectionVote =2 edlevel = 3 ageGroup1 = 5 female=1  Inc=1) atmeans noatlegend saving (margins_c2, replace)
estimates store margins_c2

combomarginsplot margins_c2, recast(line) xline(8) xlabel(,labsize(vsmall) angle(45)) xtitle("_", col(white)) ///
	scheme(plotplain) ///
	plot1opt(lcolor(gs9) lpattern(dot)) plot2opt(lcolor(black) lpattern(solid)) plot3opt(lcolor(gs6) lpattern(solid)) ci1opt(color(gs12)) ci2opt(color(gs0)) ci3opt(color(gs8)) ///
	title(Economy Got Better in last 12 months) saving(econretro_gen_cue, replace)

	

esttab cue1 cue2 using cue_test.tex, replace label nogap onecell se ar2  


 

 
clear


